package project.euler;

/**
 * The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
 * Find the sum of all the primes below two million.
 * 
 * <a href="http://projecteuler.net/index.php?section=problems&id=10">Problem 10</a>
 * 
 * @author Shekhar
 *
 */
public class PE10 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int limit = 2000000;
		boolean[] notPrimes = new boolean[limit+1];
		
		for(int divisor = 2; divisor*divisor < limit; divisor++){
			if(notPrimes[divisor] == false){
				for(int i = divisor*2 ; i <= limit ; i = i + divisor){
					notPrimes[i] = true;
				}
			}
		}
		
		long sum = 0;
		for(int i = 2;i<= limit;i++){
			if(notPrimes[i] == false){
				sum += i;
			}
		}
		
		System.out.println(sum);
	}

}
